<table id="dg-xgs" style="height:100%;width: 100%;">
    <thead>
    <tr>
        <th field="ck" checkbox="true"></th>
        <th data-options="field:'GS_MC',width:100">公司名称</th>
        <th data-options="field:'GSB_MC',width:100">小公司名称</th>
        <th data-options="field:'GSB_JC',width:100">小公司简称</th>
        <th data-options="field:'JSFS',formatter:jsfsFormatter,width:100">计算方式</th>
        <th data-options="field:'XY_BZ',formatter:BzFormatter,width:100">选用标志</th>
        <th data-options="field:'YX_BZ',formatter:BzFormatter,width:100">有效标志</th>
        <th data-options="field:'LRSJ',formatter:DateTimeFormatter,width:100">创建日期</th>
        <th data-options="field:'button',align:'center',formatter:button,width:100">操作</th>
    </tr>
    </thead>
</table>

<div id="tb-xgs">
    <table cellpadding="0" cellspacing="0" style="width:100%">
        <tr class="clearfix">
            <td class="luck-tool-button">
                公司: <select class="easyui-combobox" panelHeight="auto" data-options="prompt:'请选择',url:'${ctxPath}/dm/cxgs', method:'get', valueField:'gsId', textField:'gsMc',editable:true,width:150" id="dg_xgs_dgs" name="dg_xgs_dgs"></select>
                小公司: <input class="easyui-textbox" name="dg_xgs_xgsmc" id="dg_xgs_xgsmc" style="width:150px">
                <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="xgs_tool.search();">${i18n('btn.search')}</a>
            </td>
            <td class="luck-tool-button luck-text-right luck-right">
                <a href="#" class="easyui-linkbutton button-blue" plain="true" onclick="xgs_tool.add();"><i class="fa fa-plus fa-lg"></i>&nbsp;${i18n('btn.new')}</a>
                <a href="#" class="easyui-linkbutton button-info" plain="true" onclick="xgs_tool.import();"><i class="fa fa-file-excel-o fa-lg"></i>&nbsp;${i18n('btn.import')}</a>
                <a href="#" class="easyui-linkbutton button-red" plain="true" onclick="xgs_tool.delete();"><i class="fa fa-close fa-lg"></i>&nbsp;${i18n('btn.delete')}</a>
                <a href="#" class="easyui-linkbutton button-green" plain="true" onclick="xgs_tool.download();"><i class="fa fa-download fa-lg"></i>&nbsp;${i18n('btn.mb')}</a>
            </td>
        </tr>
    </table>
</div>
<script>
    var dg_xgs;
    $(function () {
        dg_xgs = rsdp.createDataGrid({
            tid: "dg-xgs",
            url: "${ctxPath}/system/xgs/manage",
            idField: "GSB_ID",
            loadMsg: "${i18n('oper.loading')}",
            singleSelect: false,
            tbid: "tb-xgs",
            onLoadSuccess: function () {
                $('.button-edit').linkbutton({});
                $('#oper_btn_edit').on('click', function () {
                    $('#dg-xgs').datagrid('selectRow', $(this).attr("data-index"));
                    xgs_tool.edit();
                });
            }
        });

    });

    var xgs_tool = {
        add: function () {
            rsdp.createDialog({
                url: "${ctxPath}/system/xgs/add",
                title: "${i18n('msg.xgs.new')}",
                width: 500,
                height: 400,
                btnArray: [{
                    cls: 'easyui-linkbutton button-blue',
                    iconCls: 'fa fa-check fa-lg',
                    text: "${i18n('btn.save')}",
                    handler: function () {
                        xgs_tool.add_save();
                    }
                },
                    {
                        iconCls: 'fa fa-close fa-lg',
                        text: "${i18n('btn.close')}",
                        handler: function () {
                            rsdp.closeDialog();
                        }
                    }]
            });
            //清除关闭数据没清空问题
            $("#form-add").form('clear');
        },
        add_save: function () {
            rsdp.ajaxform({
                fid: "form-add",
                url: "${ctxPath}/system/xgs/addSave",
                func: function () {
                    rsdp.closeDialog();
                    dg_xgs.datagrid("reload");
                    dg_xgs.datagrid("clearChecked");
                }
            });
        },
        edit: function () {
            var row = getSelectRow('#dg-xgs');
            if (row) {
                rsdp.createDialog({
                    url: "${ctxPath}/system/xgs/edit",
                    title: "${i18n('msg.xgs.edit')}",
                    width: 500,
                    height: 400,
                    param: {id: row.GSB_ID},
                    btnArray: [{
                        cls: 'easyui-linkbutton button-blue',
                        iconCls: 'fa fa-check fa-lg',
                        text: "${i18n('btn.save')}",
                        handler: function () {
                            xgs_tool.edit_save();
                        }
                    },
                        {
                            iconCls: 'fa fa-close fa-lg',
                            text: "${i18n('btn.close')}",
                            handler: function () {
                                rsdp.closeDialog();
                            }
                        }]
                });
            }
            else {
                //layer.msg("${i18n('msg.row.select')}", {time: 1000});
                rsdp.msg("${i18n('msg.row.select')}", {time: 1000});
            }
        },
        edit_save: function () {
            rsdp.ajaxform({
                fid: "form-edit",
                url: "${ctxPath}/system/xgs/editSave",
                func: function () {
                    rsdp.closeDialog();
                    dg_xgs.datagrid("reload");
                    dg_xgs.datagrid("clearChecked");
                }
            });
        },
        import: function () {
            rsdp.createDialog({
                url: "${ctxPath}/system/xgs/import",
                title: "${i18n('msg.xgs.import')}",
                width: 500,
                height: 200,
                btnArray: [{
                    cls: 'easyui-linkbutton button-blue',
                    iconCls: 'fa fa-check fa-lg',
                    text: "${i18n('btn.save')}",
                    handler: function () {
                        xgs_tool.import_save();
                    }
                },
                    {
                        iconCls: 'fa fa-close fa-lg',
                        text: "${i18n('btn.close')}",
                        handler: function () {
                            rsdp.closeDialog();
                        }
                    }]
            });
        },
        import_save: function () {
            rsdp.ajaxUpload({
                fid: 'form-import',
                url: "${ctxPath}/system/xgs/importSave",
                loading: "${i18n('oper.upload')}",
                success: function () {
                    rsdp.closeDialog();
                    dg_xgs.datagrid("reload");
                    dg_xgs.datagrid("clearChecked");
                    $("#dg_xgs_dgs").combobox("reload");
                }

            });
        },
        refresh: function () {
            rsdp.refresh();
        },
        search: function () {
            dg_xgs.datagrid('load', {
                gs: $('#dg_xgs_dgs').combobox('getValue'),
                xgs: $('#dg_xgs_xgsmc').val()
            });
            dg_xgs.datagrid("clearChecked");
        },
        delete: function () {
            var rows = getCheckedRows('#dg-xgs');
            //console.log(rows);
            //console.log(rows.length);
            if (rows.length > 0) {
                var strIds = "";
                //拼接字符串，这里也可以使用数组，作用一样
                for (var i = 0; i < rows.length; i++) {
                    strIds += rows[i].GSB_ID + ",";
                }
                rsdp.ajaxPostJson({
                    url: "${ctxPath}/system/xgs/delete",
                    param: {"id": strIds},
                    cstr: "${i18n('msg.xgs.delete')}",
                    func: function () {
                        dg_xgs.datagrid("reload");
                        dg_xgs.datagrid("clearChecked");
                    }
                });
            }
            else {
                //layer.msg("${i18n('msg.row.selectm')}", {time: 1000});
                rsdp.msg("${i18n('msg.row.selectm')}", {time: 1000});
            }
        },
        download: function () {
            var form = $("<form>");
            form.attr('style', 'display:none');
            form.attr('target', '');
            form.attr('method', 'post');
            form.attr('action', "${ctxPath}/system/xgs/download");
            $('body').append(form);
            form.submit();
            form.remove();
        }
    }
    function jsfsFormatter(value, row, index){
    		return value=="0"?"整数计数":"四舍五入";
    }
</script>